package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Product;
import cn.wolfcode.trip.base.domain.ProductByUser;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.mapper.ProductByUserMapper;
import cn.wolfcode.trip.base.query.ProductQuery;
import cn.wolfcode.trip.base.service.IProductByUserService;
import cn.wolfcode.trip.base.util.UserContext;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductByUserServiceImpl implements IProductByUserService {

    @Autowired
    private ProductByUserMapper productByUserMapper;

    @Override
    public PageInfo query(ProductQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<ProductByUser> list = productByUserMapper.selectByUserId(qo);
        return new PageInfo(list);
    }

    @Override
    public void add(Long userId,Long productId) {
        User u=new User();
        u.setId(userId);

        Product p=new Product();
        p.setId(productId);

        ProductByUser pb=new ProductByUser();
        pb.setUser(u);
        pb.setProduct(p);

        productByUserMapper.insert(pb);
    }

    @Override
    public void deleteByCarId(Long userId, Long productCarId) {
        productByUserMapper.deleteByCarId(userId,productCarId);
    }

}
